package com.hfh.jdbc;

import com.mysql.jdbc.Driver;
import java.sql.*;

/**
 * @Author hfh
 * @Date 2022 09 16 21 21
 **/
public class JDBCTest {

    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

//            Driver driver = new com.mysql.jdbc.Driver();
//            DriverManager.registerDriver(driver);

            String url = "jdbc:mysql://localhost:3306/poetry";
            String user = "root";
            String password = "123456";

            conn = DriverManager.getConnection(url,user,password);
            System.out.println(conn);

            stmt = conn.createStatement();

            String sql = "INSERT INTO emp VALUES(6,00006,\"张飞\",\"男\",20,2001,\"2001-02-12\")";
            int count = stmt.executeUpdate(sql);
            System.out.println(count);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                if(stmt!=null){
                    stmt.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if(conn!=null){
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
